package com.qidianit.mes.md.controller;

import com.qidianit.common.pojo.MESResult;
import com.qidianit.mes.pojo.Material;
import com.qidianit.mes.md.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author djl
 * @Time 2024/10/14 20:26
 */
@RestController
@CrossOrigin
@RequestMapping("/material")
public class MaterialController {
    @Autowired
    private MaterialService materialService;
    @GetMapping("/list")
    public MESResult selectByPage(Material material,
                                  @RequestParam(defaultValue = "1")int page,
                                  @RequestParam(defaultValue = "10")int limit){
        // 这里只有一行代码，直接调用service，不处理任何业务
        return materialService.selectByPage(material,page,limit);
    }
    @PostMapping("/save")
    public MESResult save(@RequestBody Material material) {
        return  materialService.save(material);
    }
    @PutMapping("/update")
    public MESResult update(@RequestBody Material material) {
        return materialService.updateMaterial(material);
    }

    @GetMapping("selectById")
    public MESResult selectById(Long materialId) {
        return materialService.selectById(materialId);
    }

    @DeleteMapping("/delete")
    public MESResult delete(Long materialId){
        return materialService.delete(materialId);
    }

    @DeleteMapping("/deletes")
    public MESResult deletes(String [] materialId){
        return materialService.deletes(materialId);
    }

    @GetMapping("/getAllMaterial")
    public MESResult getAllMaterial() {
        return materialService.getAllMaterial();
    }
}